/**
 * @func 基于localStorage封装Storage类,单例模式
 * @author Ken_Wen
 * @date 2024-08-20
 */

// 语法糖
class Storage {
  // static instance;
  static getInstance() {
    // JS 动态  static 属性
    // JS 没有类，都是对象
    if (!Storage.instance) {
      Storage.instance = new Storage();
    }

    return Storage.instance;
  }

  getItem(key) {
    return localStorage.setItem(key, value);
  }

  setItem(key, value) {
    localStorage.setItem(key, value);
  }
}

export default Storage;

// function Storage(name) {
//   this.name = name;
// }

// Storage.prototype.setName = function (newName) {
//   this.name = newName;
// };

// const storage = new Storage('Ken');
// const storage1 = new Storage('Xie');

// console.log(storage.name);
// console.log(storage1.name);

// storage.setName('Wen');
// console.log(storage);
// console.log(storage1);
